/**
 * Created by sinrin on 2017/8/15.
 */
$(function () {
    pageInit();
});
function pageInit() {
    var ctx = 'http://localhost:8080';
    jQuery("#list10").jqGrid(
        {
            url: ctx + '/JSONData',
            datatype: "json",
            colNames: ['时间段', '无不良', '不良数量', '备注'],
            colModel: [
                {name: 'timeSpan', index: 'timeSpan', width: 55, sortable: false},
                {name: 'allGoodFlag', index: 'allGoodFlag', width: 90, sortable: false},
                {name: 'badQty', index: 'badQty', width: 100, sortable: false},
                {name: 'comment', index: 'comment', width: 80, align: "right", sortable: false}
            ],
            rowNum: 24,
            // rowList: [10, 20, 30],
            // pager: '#pager10',
            // sortname: 'id',
            viewrecords: true,
            sortorder: "desc",
            multiselect: false,
            caption: "老化不良记录表",
            onSelectRow: function (ids) {
                if (ids == null) {
                    ids = 0;
                    if (jQuery("#list10_d").jqGrid('getGridParam',
                            'records') > 0) {
                        jQuery("#list10_d").jqGrid(
                            'setGridParam',
                            {
                                url: ctx + "/SubGrid?q=1&id="
                                + ids,
                                page: 1
                            });
                        jQuery("#list10_d").jqGrid('setCaption',
                            "Invoice Detail: " + ids).trigger(
                            'reloadGrid');
                    }
                } else {
                    jQuery("#list10_d").jqGrid('setGridParam', {
                        url: ctx + "/SubGrid?q=1&id=" + ids,
                        page: 1
                    });
                    jQuery("#list10_d").jqGrid('setCaption',
                        "Invoice Detail: " + ids).trigger(
                        'reloadGrid');
                }
            }
        });
    jQuery("#list10").jqGrid('navGrid', '#pager10', {
        add: false,
        edit: false,
        del: false
    });
    jQuery("#list10_d").jqGrid({
        height: 100,
        url: ctx + '/SubGrid?q=1&id=0',
        datatype: "json",
        colNames: ['不良项目', '数量', '备注'],
        colModel: [
            {name: 'num', index: 'num', width: 180, sortable: false, search: false},
            {name: 'item', index: 'item', width: 50, sortable: false, search: false},
            {name: 'qty', index: 'qty', width: 180, align: "left", sortable: false, search: false}
        ],
        rowNum: 10,
        // rowList: [5, 10, 20],
        // pager: '#pager10_d',
        // sortname: 'item',
        viewrecords: true,
        // sortorder: "asc",
        multiselect: false,
        caption: "Invoice Detail"
    }).navGrid('#pager10_d', {
        add: true,
        edit: true,
        del: true
    });
    jQuery("#ms1").click(function () {
        var s;
        s = jQuery("#list10_d").jqGrid('getGridParam', 'selarrrow');
        alert(s);
    });
}